﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Eisk.BusinessLogicLayer;
using Eisk.Helpers;

namespace Eisk.Web
{
    public partial class view_suppliers : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {            
        }

        protected void ButtonDeleteSelected_Click(object sender, System.EventArgs e)
        {
            try
            {
                string status = string.Empty;
                List<Int32> supplierIDsToDelete = new List<Int32>();

                foreach (GridViewRow row in gridViewSuppliers.Rows)
                {
                    CheckBox cb = (CheckBox)(row.FindControl("chkEmployeeSelector"));
                    if (cb != null && cb.Checked)
                    {
                        Int32 supplierId = (Int32)gridViewSuppliers.DataKeys[row.RowIndex].Value;

                        supplierIDsToDelete.Add(supplierId);

                        status += String.Format(MessageFormatter.GetFormattedSuccessMessage("Delete successful. Supply Id {0} has been deleted"), supplierId);
                    }
                }
                new SupplierBLL().DeleteSuppliers(supplierIDsToDelete);
                ltlMessage.Text = status;
            }
            catch (Exception ex)
            {
                ltlMessage.Text = ltlMessage.Text += String.Format(MessageFormatter.GetFormattedErrorMessage("Cannot Delete! Error " + ex.Message));
            }
            gridViewSuppliers.PageIndex = 0;
            gridViewSuppliers.DataBind();
        }

        protected void ButtonAddNewSupplier_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("add-supplier.aspx");
        }
    }
}